package com.tau.egonetwork.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;

import com.tau.egonetwork.common.Log;

public class ExcelHelpDialog extends Dialog {

	public ExcelHelpDialog(Shell parent) {
		super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
	}

	public void open() {
		
		Shell shell = new Shell(getParent(), getStyle());
		shell.setText("Excel import - Help");
		
		populate(shell);
		
		shell.pack();
		
		//set shell at the center of display:
	    Monitor primary = getParent().getMonitor();
	    Rectangle bounds = primary.getBounds();
	    Rectangle rect = shell.getBounds();
	    int x = bounds.x + (bounds.width - rect.width) / 2;
	    int y = bounds.y + (bounds.height - rect.height) / 2;
	    shell.setLocation(x, y);
		
		Log.writeLineToLog("opening dialog");

		shell.open();
		
		//keep shell open, waiting for user input:
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	private void populate(Shell shell) {
		
		GridLayout layout = new GridLayout(1, false);
		layout.marginRight = 40;
		layout.marginLeft = 40;
		layout.marginTop = 15;
		layout.marginBottom = 20;
		shell.setLayout(layout);
		shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		
		
		new Label(shell, SWT.NONE).setText("- File name will be egocentric profile name.");
		new Label(shell, SWT.NONE).setText("- First Sheet:");		
		new Label(shell, SWT.NONE).setText("\t- Cell A1 must be profile type. Either Faceboor or Linkedin.");
		new Label(shell, SWT.NONE).setText("\t- First row and first column list names of friends.");
		new Label(shell, SWT.NONE).setText("\t- Names in first row and first column must be identidical and in the same order.");
		new Label(shell, SWT.NONE).setText("\t- Highly recommended to give distinct names.");
		new Label(shell, SWT.NONE).setText("\t- Each cell in matrix must be either 0 or 1.");
		new Label(shell, SWT.NONE).setText("\t- Values must match (i.e. B3 and C2 should have the same value)");
		new Label(shell, SWT.NONE).setText("\t- Value of main diagonal not important.");
		new Label(shell, SWT.NONE).setText(" ");
		new Label(shell, SWT.NONE).setText("- Second Sheet:");
		new Label(shell, SWT.NONE).setText("\t- Each row represents a group.");
		new Label(shell, SWT.NONE).setText("\t- First column is group's name.");
		new Label(shell, SWT.NONE).setText("\t- Rests of columns for that row is group members.");
		new Label(shell, SWT.NONE).setText("\t- Group members must exist in first sheet.");
		
	}
		
}
